<!DOCTYPE html>
<html lang="en">
<head>
    <!--js include-->
    {{template "/chat/head.shtml"}}
</head>
<body>
<header class="mui-bar mui-bar-nav">
    <h1 class="mui-title">注册</h1>
</header>
{{.}}
<div class="mui-content" id="pageapp">
    <form id='login-form' class="mui-input-group">
        <div class="mui-input-row">
            <label>账号</label>
            <input v-model="user.name" placeholder="请输入用户名" type="text" class="mui-input-clear mui-input">
        </div>
        <div class="mui-input-row">
            <label>密码</label>
            <input v-model="user.password" placeholder="请输入密码" type="password" class="mui-input-clear mui-input">
        </div>
        <div class="mui-input-row">
            <label>密码</label>
            <input v-model="user.identity" placeholder="请输入密码" type="password" class="mui-input-clear mui-input">
        </div>
    </form>
    <div class="mui-content-padded">
        <button @click="login" type="button" class="mui-btn mui-btn-block mui-btn-primary">注册</button>
        <div class="link-area">
            <a id='reg' href="/index">登录账号</a>
            <span class="spliter">|</span> <a id='forgetPassword'>忘记密码</a>
        </div>
    </div>
    <div class="mui-content-padded oauth-area">
    </div>
</div>

<script>
    var app = new Vue({
        el: "#pageapp",
        data: function () {
            return {
                user: {
                    name: "",
                    password: "",
                    identity: ""
                }
            }
        },
        methods: {
            login: function () {
                console.log("User data:", this.user);

                util.post("/user/createUser", this.user).then(res => {
                    console.log(res)
                    if (res.code !== 0) {
                        mui.toast(res.msg)
                    } else {
                        location.replace("/index")
                        mui.toast("Registration successful and will be redirected soon")
                    }
                })
            },
        }
    })
</script>
</body>
</html>